﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Path.Question;
namespace Path.Answer
{
    class Jimson : IPath
    {
        public string GetRelativePath(string currentPath, string targetPath)
        {
            string[] Curpathes = currentPath.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            string[] TarPath = targetPath.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            Queue<string> Curpa = new Queue<string>();
            Queue<string> Tarpa = new Queue<string>();

            string res = "";

            foreach (var item in Curpathes)
            {
                Curpa.Enqueue(item);
            }
            foreach (var item in TarPath)
            {
                Tarpa.Enqueue(item);
            }

            while (Curpa.Count > 0)
            {
                if (Tarpa.Count == 0 || Curpa.Peek() != Tarpa.Peek())
                {
                    res += "../";
                    Curpa.Dequeue();
                    break;
                }
                Curpa.Dequeue();
                Tarpa.Dequeue();
            }

            while (Curpa.Count > 0)
            {
                res += "../";
                Curpa.Dequeue();
            }

            while (Tarpa.Count > 0)
            {
                res += Tarpa.Dequeue() + "/";
            }
            return res.Remove(res.Length -1);
        }
    }
}
